import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import get from '@dfeidao/atom-web/local/get';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';

import error from '@dfeidao/atom-web/msgbox/error';
import success from '@dfeidao/atom-web/msgbox/success';
import P06 from './P06';
export default async function a007(fd: IFeidaoAiBrowserComponent) {

	const tenantid = get(fd, 'tenantid') as string;
	const productid = get(fd, 'productid') as string;
	const select1 = fd.data.node.querySelector<HTMLSelectElement>('[select]');
	const index = select1.options.selectedIndex;
	const client_type1 = select1.options[index].value;
	if (!tenantid) {
		await error('请先选择租户！');
		return;
	}
	const a = get(fd, 'origin_obj') as Map<string, { left: {}, right: Array<{}> }>;
	const newarr = Array.from(a.values());
	console.log(newarr);
	// d_data = newarr.filter((nm: { left: { formid: string } }) => {
	// 	return nm.formid === ;
	// });
	const res1 = await nodejs('tenant-function/zj-000001/s003',
		{ newarr, tenantid, productid, client_type: client_type1 }
	);

	if (res1 === 'success') {
		success('保存成功');
		render(fd, '', P06, "P06", "inner");
		return;
	} else {
		error('保存失败');
	}
}
